package com.yeshine.opendata.utils;

import org.springframework.util.FileCopyUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by taohj on 2014/7/21.
 */
public class FileUtils {

    public static void copy(InputStream inputStream, File target) throws IOException {
        if (!target.getParentFile().exists()) {
            target.getParentFile().mkdirs();
        }
        FileCopyUtils.copy(inputStream, new FileOutputStream(target));
    }

    public static void copy(File source, File target) throws IOException {
        if (!target.getParentFile().exists()) {
            target.getParentFile().mkdirs();
        }
        FileCopyUtils.copy(source, target);
    }
    public  static void remove(String filepath) throws IOException {
        File file=new File(filepath);
        if (file.exists()){
            System.out.println("delete filepath:"+filepath);
            org.apache.commons.io.FileUtils.forceDeleteOnExit(file);
        }
    }

}
